package generator.statements;

import generator.addons.SimpleDataGenerator;
import generator.collections.AttractionAvailabilityTable;
import java.util.Date;

/**
 * AttractionAvailability SQL record mapper.
 * 
 * @author Necro
 * @author Marek Snopkowski <snpy@snpy.info>
 * @version 11.04.2008
 */
public class AttractionAvailability extends Statement 
{
    private int availabilityID;
    
    private Attraction attraction;
    private Date startDate;
    private Date endDate;

    public AttractionAvailability(Attraction attraction, Date startDate, Date endDate) 
    {        
        this.availabilityID = AttractionAvailabilityTable.autoincrement();        
        this.attraction     = attraction;
        this.startDate      = startDate;
        this.endDate        = endDate;
    }
    
    public AttractionAvailability(Attraction attraction)
    {
        this(attraction, null, null);
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }
    
    @Override
    public int getId()
    {
        return availabilityID;
    }
    
    public Object[] getFieldsValueCollection()
    {
        return new Object[]{ availabilityID, attraction.getId(), startDate, endDate };
    }
    
    public String getFieldsNameSet()
    {
        return "[availability_id], [attraction_id], [start_date], [end_date]";
    }
    
    public static AttractionAvailability genRand(Attraction attraction)
    {        
        AttractionAvailability result = new AttractionAvailability(attraction);
                
        if (attraction.getName().equals("Narciarstwo w Alpach")){
            result.setStartDate(SimpleDataGenerator.getDate(8, 9));
            result.setEndDate(SimpleDataGenerator.getDate(10, 11));
        } else if (attraction.getName().equals("Oglądanie Stonehenge")){
            result.setStartDate(SimpleDataGenerator.getDate(2, 3));
            result.setEndDate(SimpleDataGenerator.getDate(9, 10));
        } else if (attraction.getName().equals("Wizyta w DisneyLand")){
            result.setStartDate(SimpleDataGenerator.getDate(2, 3));
            result.setEndDate(SimpleDataGenerator.getDate(9, 10));
        } else if (attraction.getName().equals("Przejażdżka na wielbłądzie")){
            result.setStartDate(SimpleDataGenerator.getDate(4, 5));
            result.setEndDate(SimpleDataGenerator.getDate(9, 10));
        } else {
            return null;
        }
        
        return result;
    }
    
     @Override
    public String getTableName()
    {
        return "attraction_availability";
    }
}
